package com.example.entity;

import lombok.Data;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;

@Data
public class TicketDetail {
    int id;
    int order_id;
    int passenger_id;
    String passenger_name;
    String passenger_type;
    int flightNo;
    String date;
    double price;
    String seat_type;
    String seat;
    String status;
    String statusText; //已出票、已完成、已取消、待支付、待退款
    //flight
    String departure_airport;
    String arrival_airport;
    String departure_city;
    String arrival_city;
    String departure_date;
    String departure_day;
    String departure_time;
    String arrival_date;
    String arrival_day;
    String arrival_time;
    String baggage_limit;
    String meal;
    String meal_money;
    String gate;
    //plane
    int plane_id;
    String p_model;
    String p_airline;
    int plane_age;
    String WiFi;
    //order
    String paymentDeadline;
    String refundDate;

    public String getTicket_id() {
        String formattedDate = date.replace("-", "");
        return "HL" + formattedDate + "-" + String.format("%04d", id);
    }
    public String getFlight_id() {
        if (Objects.equals(p_airline, "南方航空公司")){
            return "CZ" + String.format("%05d", plane_id);
        }else if(Objects.equals(p_airline, "东方航空公司")){
            return "MU" + String.format("%05d", plane_id);
        } else if (Objects.equals(p_airline, "中国国际航空公司")) {
            return "CA" + String.format("%05d", plane_id);
        } else{
            return "N/A";
        }
    }
    public String getDuration() {
        try {
            SimpleDateFormat format = new SimpleDateFormat("HH:mm");
            Date dep = format.parse(getDeparture_time());
            Date arr = format.parse(getArrival_time());
            long diff = arr.getTime() - dep.getTime();
            long minutes = diff / (60 * 1000); // 转换为分钟
            long hours = minutes / 60;
            minutes = minutes % 60;
            return hours + "h " + minutes + "m";
        } catch (Exception e) {
            return "N/A"; // 出错时返回默认值
        }
    }
}
